﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Users;
using System.Data;

namespace LogicServer.Users
{
    public class UserLogic
    {
        /// <summary>
        /// 根据用户名得到密码
        /// </summary>
        /// <param name="name">登录账号</param>
        /// <returns>密码</returns>
        public String GetPwdByUid(String uid)
        {
            UserData ud = new UserData();
            return ud.GetPassWordByUser(uid);
        }

        /// <summary>
        /// 根据用户名得到用户对象
        /// </summary>
        /// <param name="uid">登录用户名</param>
        /// <returns>User对象</returns>
        public Model.Users GetUserByUid(String uid)
        {
            Model.Users user = new Model.Users();
            UserData ud = new UserData();
            
            user = ud.GetUserByUid(uid);
            if (user == null)
            {
                return null;
            }
            return user;
        }

        /// <summary>
        /// 根据用户id得到用户对象
        /// </summary>
        /// <param name="uid">登录用户名</param>
        /// <returns>User对象</returns>
        public Model.Users GetUserById(String id)
        {
            Model.Users user = new Model.Users();
            UserData ud = new UserData();

            user = ud.GetUserById(id);
            if (user == null)
            {
                return null;
            }
            return user;
        }

        /// <summary>
        /// 注册新用户
        /// </summary>
        /// <param name="user">user实例</param>
        /// <returns>int result</returns>
        public int AddUser(Model.Users user)
        {
            UserData ud = new UserData();
            return ud.InsertUser(user);
        }

        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int DeleteUser(string id)
        {
            UserData ud = new UserData();
            return ud.DeleteUser(id);
        }

        /// <summary>
        /// 获取所有用户
        /// </summary>
        /// <returns></returns>
        public DataTable GetAllUser() 
        {
            UserData ud = new UserData();
            return ud.GetUsers();
        }
    }
}
